package com.tuanbiao.models.action;

import androidx.annotation.NonNull;

import com.hzjq.data.callback.Callback;
import com.hzjq.data.callback.HttpCallback;
import com.hzjq.data.hzjq.entity.CapRecordEntity;
import com.hzjq.data.minbao.entity.AuthEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.callback.ResultCallback;
import com.hzjq.lib.loader.DBLoader;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import java.io.File;
import java.util.List;

/**
 * @author abiao
 * @since 2022/4/22 15:33
 */
public interface AuthAction {
    default void checkAuth(List<CapRecordEntity> entities, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        BlastKool.Companion.loader().authCap().authLocal(entities, new HttpCallback<List<CapRecordEntity>>() {
            @Override
            public void onSuccess(List<CapRecordEntity> entities) {
                callback.onSuccess(entities);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void authLocal(List<CapRecordEntity> entities, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        BlastKool.Companion.loader().authCap().authLocal(entities, new HttpCallback<List<CapRecordEntity>>() {
            @Override
            public void onSuccess(List<CapRecordEntity> entities) {
                callback.onSuccess(entities);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void authNet(List<CapRecordEntity> entities, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        authNet(true, entities, callback);
    }

    default void authNet(boolean showLoading, List<CapRecordEntity> entities, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        BlastKool.Companion.loader().authCap().authNet(showLoading, entities, new HttpCallback<List<CapRecordEntity>>() {
            @Override
            public void onSuccess(List<CapRecordEntity> entities) {
                callback.onSuccess(entities);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void clearExpireAuthFile() {
        BlastKool.Companion.loader().authCap().startClearExpireAuthFileTask();
    }

    default void auth(List<CapRecordEntity> entities, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        auth(entities, true, callback);
    }

    default void auth(List<CapRecordEntity> entities, boolean showLoading, OnBaseResultCallback<List<CapRecordEntity>> callback) {
        BlastKool.Companion.loader().quick().auth(entities, showLoading, new HttpCallback<List<CapRecordEntity>>() {
            @Override
            public void onSuccess(List<CapRecordEntity> entities) {
                callback.onSuccess(entities);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void authOffline(List<String> uidList, OnBaseResultCallback<AuthEntity> callback) {
        BlastKool.Companion.loader().http().loadAuthByBox(uidList, new HttpCallback<AuthEntity>() {
            @Override
            public void onSuccess(AuthEntity entity) {
                callback.onSuccess(entity);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    /**
     * 验证码获取授权文件
     *
     * @param code
     * @param callback
     */
    default void loadAuthByCode(String code, OnBaseResultCallback<AuthEntity> callback) {
        BlastKool.Companion.loader().http().loadAuthByCode(code, new HttpCallback<AuthEntity>() {
            @Override
            public void onSuccess(AuthEntity authEntity) {
                callback.onSuccess(authEntity);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void parseAuthFile(File file, String password, OnBaseResultCallback<AuthEntity> callback) {
        BlastKool.Companion.loader().parseAuthFile(password, file, new ResultCallback<AuthEntity>() {
            @Override
            public void onSuccess(AuthEntity entity) {
                callback.onSuccess(entity);
                callback.onFinish();
            }

            @Override
            public void onFailed(@NonNull String s) {
                callback.onFailed(s);
                callback.onFinish();
            }
        });
    }

    default void queryAuth(int pageIndex, OnBaseResultCallback<List<AuthEntity>> callback) {
        DBLoader.Companion.getLoader().queryAuth(pageIndex, new Callback<List<AuthEntity>>() {
            @Override
            public void run(List<AuthEntity> authEntities) {
                callback.onSuccess(authEntities);
                callback.onFinish();
            }
        });

    }

    default void deleteAuth(AuthEntity entity, OnBaseResultCallback<Void> callback) {
        DBLoader.Companion.getLoader().deleteAuth(entity, new Runnable() {
            @Override
            public void run() {
                callback.onSuccess(null);
                callback.onFinish();
            }
        });
    }
}
